package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcWorkLogMapper;
import com.csun.cmny.provider.dto.OmcWorkLogDto;
import com.csun.cmny.provider.model.domain.OmcWorkLog;
import com.csun.cmny.provider.service.OmcWorkLogService;
import com.csun.cmny.util.PublicUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-08-08 14:12
 * @Description: the class omc work log service impl
 */
@Service
@Transactional
public class OmcWorkLogServiceImpl extends BaseService<OmcWorkLog> implements OmcWorkLogService {

    @Resource
    private OmcWorkLogMapper omcWorkLogMapper;

    /**
     * 保存工作日志
     *
     * @param omcWorkLogDto the omc work log dto
     * @param loginAuthDto  the login auth dto
     *
     * @return  the int.
     */
    @Override
    public Integer saveWorkLog(OmcWorkLogDto omcWorkLogDto, LoginAuthDto loginAuthDto) {

        OmcWorkLog omcWorkLog = new OmcWorkLog();
        omcWorkLog.setUserId(loginAuthDto.getUserId());
        omcWorkLog.setDate(omcWorkLogDto.getDate());

        omcWorkLog = omcWorkLogMapper.selectOne(omcWorkLog);

        if (PublicUtil.isEmpty(omcWorkLog)) {
            omcWorkLog = new OmcWorkLog();
        }

        omcWorkLog.setUpdateInfo(loginAuthDto);
        omcWorkLog.setUserId(loginAuthDto.getUserId());
        omcWorkLog.setUserName(loginAuthDto.getUserName());
        omcWorkLog.setGroupId(loginAuthDto.getGroupId());
        omcWorkLog.setDate(omcWorkLogDto.getDate());
        omcWorkLog.setWorkLog(omcWorkLogDto.getWorkLog());

        if (omcWorkLog.isNew()) {
            return omcWorkLogMapper.insertSelective(omcWorkLog);
        } else {
            return omcWorkLogMapper.updateByPrimaryKeySelective(omcWorkLog);
        }
    }
}
